package com.liu.thread_study;

import java.util.concurrent.*;

/**
 * 实现线程的三种方式
 */
public class ImplementThreadThreeMethod {

    public static void main(String[] args) {
        /* 第一种 */
        myThread myThread = new myThread();
        myThread.start();

        /* 第二种 实现runnable接口 */
        myThreadTwo myThreadTwo = new myThreadTwo();
        new Thread(myThreadTwo).start();

        /* 第三种 实现Callable接口，重写call方法 */
        myThreadThree myThreadThree = new myThreadThree();

        ExecutorService executorService = Executors.newSingleThreadExecutor();
        Future submit = executorService.submit(myThreadThree);

        try {

            System.out.println(submit.get());

        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }

}
/**
 * 第一种继承Thread类
 */
class myThread extends Thread{
    @Override
    public void run() {
        System.out.println("这是我继承Thread类，重写run方法的的结果");
    }
}
/**
 * 实现Runnable接口
 */
class myThreadTwo implements Runnable{

    public void run() {
        System.out.println("这是我实现了Runnable接口，实现run方法的结果");
    }
}

/**
 * 实现Callable接口
 */
class myThreadThree implements Callable{

    public String call() throws Exception {
        System.out.println("这是我重写call()方法，实现call方法的结果");
        return "成功";
    }
}